<template>
<div class="history-wrap">
  <div class="history-icon">
    <i class="el-icon-alarm-clock"></i>
    <span>历史记录</span>
  </div>
  <div class="history-block">
    <el-timeline>
      <el-timeline-item
          v-for="item in list"
          :key="item.videoId"
          :timestamp="item.viewDate"
          placement="top"
      >
        <el-card>
          <div class="history-item">
            <el-image @click="toCourse(item)" :src="item.courseCover"  style="width: 80px; height: 80px;margin-right: 30px;cursor: pointer"></el-image>
            <div class="r-txt">
              <a class="title" @click="toCourse(item)">{{item.courseName}}</a>
              <div>当前所处章节：{{item.chapterName}}</div>
              <div style="display: flex;flex-direction: row;justify-content: space-between">
                <div><span>观看进度 </span>{{item.viewDegree.toFixed(2)}}%</div>
              </div>
            </div>
          </div>
        </el-card>
      </el-timeline-item>
    </el-timeline>
  </div>
</div>
</template>

<script>
import {getUserHistory} from "@/api/user";

export default {
  name: "history",
  data() {
    return{
      pageSize:6,
      list:[]
    }
  },
  created() {
    this.getList()
  },
  methods:{
    getList() {
      getUserHistory({size:this.pageSize}).then(res => {
        if (res.code == 200) {
          // 拼接观看记录
          this.list = [...res.data]
          // 去重
          this.list = Array.from(new Set(this.list))
          console.log(this.list)
        }
      })
    },
    // 跳转页面
    toCourse(row) {
      const {href} = this.$router.resolve({
        path:'/course',
        query:{
          courseId:row.courseId,
          chapterId:row.chapterId,
          videoId:row.videoId
        }
      })

      window.open(href,'_blank')
    }
  }
}
</script>

<style scoped>

.history-wrap {
  width: 1160px;
  padding-top: 30px;
  margin: 0 auto;
}
.history-icon {
  font-size: 28px;
  height: 35px;
}
.history-icon i {
  color: #e3936c;
  margin-right: 15px;
}
.history-icon span {
  display: inline-block;
  height: 35px;
  font-size: 18px;
  color: #222;
  vertical-align: middle;
  line-height: 30px;
}
.history-item {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
}
.history-item .r-txt {
  display: flex;
  width: 50%;
  flex-direction: column;
  justify-content: space-between;
}
.history-item .r-txt .title {
  display: block;
  cursor: pointer;
  color: #222;
  text-overflow:ellipsis;
  white-space: nowrap;
  font-weight: 700;
  font-size: 16px;
}
.history-item .r-txt .title:hover {
  color: rgb(0, 182, 232);
}
</style>
